package com.huashi.dealer.modular.controller.store.setting;

import com.huashi.dealer.commonEntity.Express;
import com.huashi.dealer.core.pojo.CommonResult;
import com.huashi.dealer.modular.business.express.service.ExpressService;
import com.huashi.dealer.modular.business.setting.param.StoreSettingUpdateParam;
import com.huashi.dealer.modular.business.setting.service.StoreSettingService;
import com.huashi.dealer.modular.business.setting.vo.ExpressVo;
import com.huashi.dealer.modular.business.setting.vo.StoreSettingVo;
import com.huashi.dealer.modular.business.setting.param.TradeSettingUpdateParam;
import com.huashi.dealer.modular.business.setting.vo.TradeSettingVo;
import com.huashi.dealer.modular.business.setting.param.FullFreeSettingParam;
import com.huashi.dealer.modular.business.setting.vo.FullFreeSettingVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "Store端系统设置")
@RestController("storeSettingController")
@RequestMapping("/store/setting")
@Validated
public class SettingController {

    @Resource
    private StoreSettingService storeSettingService;
    @Resource
    private ExpressService expressService;

    @GetMapping("/store")
    @Operation(summary = "获取商城设置")
    public CommonResult<StoreSettingVo> getStoreSetting() {
        return CommonResult.data(storeSettingService.getStoreSetting());
    }

    @PostMapping("/store")
    @Operation(summary = "更新商城设置")
    public CommonResult<String> updateStoreSetting(@RequestBody StoreSettingUpdateParam param) {
        storeSettingService.updateStoreSetting(param);
        return CommonResult.ok("操作成功");
    }

    @GetMapping("/trade")
    @Operation(summary = "获取交易设置")
    public CommonResult<TradeSettingVo> getTradeSetting() {
        return CommonResult.data(storeSettingService.getTradeSetting());
    }

    @PostMapping("/trade")
    @Operation(summary = "更新交易设置")
    public CommonResult<String> updateTradeSetting(@RequestBody TradeSettingUpdateParam param) {
        storeSettingService.updateTradeSetting(param);
        return CommonResult.ok("操作成功");
    }

    @GetMapping("/fullFree")
    @Operation(summary = "获取满额包邮设置")
    public CommonResult<FullFreeSettingVo> getFullFreeSetting() {
        return CommonResult.data(storeSettingService.getFullFreeSetting());
    }

    @PostMapping("/fullFree")
    @Operation(summary = "更新满额包邮设置")
    public CommonResult<String> updateFullFreeSetting(@RequestBody FullFreeSettingParam param) {
        storeSettingService.updateFullFreeSetting(param);
        return CommonResult.ok("操作成功");
    }

    @GetMapping("/getExpressList")
    @Operation(summary = "获取物流公司列表")
    public CommonResult<List<ExpressVo>> getExpressList() {
        return CommonResult.data(expressService.getExpressList());
    }

    @PostMapping("/saveOrUpdateExpress")
    @Operation(summary = "保存或更新物流公司")
    public CommonResult<String> saveOrUpdateExpress(@RequestBody Express param) {
        return CommonResult.data(expressService.saveOrUpdateExpress(param));
    }

    @GetMapping("/deleteExpress/{expressId}")
    @Operation(summary = "删除物流公司")
    public CommonResult<String> deleteExpress(@PathVariable Long expressId) {
        return CommonResult.data(expressService.deleteExpress(expressId));
    }
}


